using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using THSLib;using THSERP.BaseProvider;

namespace THSERP
{
    public partial class guiLayByPayment : Form
    {
        public guiLayByPayment()
        {
            InitializeComponent();
        }

        public guiLayByPayment(double balanceDue, double depositBalance)
        {
            InitializeComponent();

            fld_lblBalanceDue.Text = THSUtil.GetNumberDisplayFormat(balanceDue);
            fld_lblDepositBalance.Text = THSUtil.GetNumberDisplayFormat(depositBalance);
            if (depositBalance > 0)
            {
                fld_lblMinimumDepositTitle.Visible = false;
                fld_lblMinimumDeposit.Visible = false;
            }
            else
            {
                //Get initial deposit from ADConfigValues
                ADConfigValuesController objConfigValuesController = new ADConfigValuesController();
                ADConfigValuesInfo objConfigValuesInfo = objConfigValuesController.GetObjectByConfigKey(Modules.LayBy.LayByModule.cstLayByConfigInitialDeposit);
                double initialPercent = Convert.ToDouble(objConfigValuesInfo.ADConfigKeyValue);
                fld_lblMinimumDeposit.Text = THSUtil.GetNumberDisplayFormat(balanceDue * initialPercent / 100);
                fld_txtPaymentAmount.Text = fld_lblMinimumDeposit.Text;
            }
        }

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
            
            if (!String.IsNullOrEmpty(fld_txtPaymentAmount.Text))
            {
                if (fld_lblMinimumDeposit.Visible)
                {
                    double paymentAmount = Convert.ToDouble(fld_txtPaymentAmount.Text);
                    double minimumDeposit = Convert.ToDouble(fld_lblMinimumDeposit.Text);
                    if (paymentAmount < minimumDeposit)
                    {
                        MessageBox.Show("The payment amount must be equal or greater than the initial minimum deposit", "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                this.Tag = fld_txtPaymentAmount.Text;   
            }
            else
                this.Tag = 0;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void fld_btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}